home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.plaf.LabelUI;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Font;
- import java.awt.Image;
-
- public class JLabel extends JComponent implements SwingConstants, Accessible {
- private int mnemonic;
- private String text;
- private Icon defaultIcon;
- private Icon disabledIcon;
- private int verticalAlignment;
- private int horizontalAlignment;
- private int verticalTextPosition;
- private int horizontalTextPosition;
- private int iconTextGap;
- protected Component labelFor;
-
- public JLabel() {
- this("", (Icon)null, 2);
- }
-
- public JLabel(Icon image) {
- this((String)null, image, 0);
- }
-
- public JLabel(Icon image, int horizontalAlignment) {
- this((String)null, image, horizontalAlignment);
- }
-
- public JLabel(String text) {
- this(text, (Icon)null, 2);
- }
-
- public JLabel(String text, int horizontalAlignment) {
- this(text, (Icon)null, horizontalAlignment);
- }
-
- public JLabel(String text, Icon icon, int horizontalAlignment) {
- this.mnemonic = 0;
- this.text = "";
- this.defaultIcon = null;
- this.disabledIcon = null;
- this.verticalAlignment = 0;
- this.horizontalAlignment = 2;
- this.verticalTextPosition = 0;
- this.horizontalTextPosition = 4;
- this.iconTextGap = 4;
- this.labelFor = null;
- this.setText(text);
- this.setIcon(icon);
- this.setHorizontalAlignment(horizontalAlignment);
- this.updateUI();
- ((JComponent)this).setAlignmentX(0.0F);
- }
-
- protected int checkHorizontalKey(int key, String message) {
- if (key != 2 && key != 0 && key != 4) {
- throw new IllegalArgumentException(message);
- } else {
- return key;
- }
- }
-
- protected int checkVerticalKey(int key, String message) {
- if (key != 1 && key != 0 && key != 3) {
- throw new IllegalArgumentException(message);
- } else {
- return key;
- }
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJLabel(this);
- }
-
- return super.accessibleContext;
- }
-
- public Icon getDisabledIcon() {
- if (this.disabledIcon == null && this.defaultIcon != null && this.defaultIcon instanceof ImageIcon) {
- Image grayImage = GrayFilter.createDisabledImage(((ImageIcon)this.defaultIcon).getImage());
- this.disabledIcon = new ImageIcon(grayImage);
- ((JComponent)this).firePropertyChange("disabledIcon", (Object)null, this.disabledIcon);
- }
-
- return this.disabledIcon;
- }
-
- public int getDisplayedMnemonic() {
- return this.mnemonic;
- }
-
- public int getHorizontalAlignment() {
- return this.horizontalAlignment;
- }
-
- public int getHorizontalTextPosition() {
- return this.horizontalTextPosition;
- }
-
- public Icon getIcon() {
- return this.defaultIcon;
- }
-
- public int getIconTextGap() {
- return this.iconTextGap;
- }
-
- public Component getLabelFor() {
- return this.labelFor;
- }
-
- public String getText() {
- return this.text;
- }
-
- public LabelUI getUI() {
- return (LabelUI)super.ui;
- }
-
- public String getUIClassID() {
- return "LabelUI";
- }
-
- public int getVerticalAlignment() {
- return this.verticalAlignment;
- }
-
- public int getVerticalTextPosition() {
- return this.verticalTextPosition;
- }
-
- public void setDisabledIcon(Icon disabledIcon) {
- Icon oldValue = this.disabledIcon;
- this.disabledIcon = disabledIcon;
- ((JComponent)this).firePropertyChange("disabledIcon", oldValue, disabledIcon);
- ((Component)this).repaint(10L);
- }
-
- public void setDisplayedMnemonic(char aChar) {
- int vk = aChar;
- if (aChar >= 'a' && aChar <= 'z') {
- vk = aChar - 32;
- }
-
- this.setDisplayedMnemonic(vk);
- }
-
- public void setDisplayedMnemonic(int key) {
- int oldKey = this.mnemonic;
- this.mnemonic = key;
- ((JComponent)this).firePropertyChange("displayedMnemonic", oldKey, this.mnemonic);
- ((Component)this).repaint();
- }
-
- public void setFont(Font font) {
- super.setFont(font);
- ((Component)this).repaint(10L);
- }
-
- public void setHorizontalAlignment(int alignment) {
- if (alignment != this.horizontalAlignment) {
- int oldValue = this.horizontalAlignment;
- this.horizontalAlignment = this.checkHorizontalKey(alignment, "horizontalAlignment");
- ((JComponent)this).firePropertyChange("horizontalAlignment", oldValue, this.horizontalAlignment);
- ((Component)this).repaint(10L);
- }
- }
-
- public void setHorizontalTextPosition(int x) {
- if (x != this.horizontalTextPosition) {
- this.horizontalTextPosition = this.checkHorizontalKey(x, "horizontalTextPosition");
- ((Component)this).repaint(10L);
- }
- }
-
- public void setIcon(Icon icon) {
- this.defaultIcon = icon;
- ((JComponent)this).firePropertyChange("icon", icon, this.defaultIcon);
- if (super.accessibleContext != null && icon != this.defaultIcon) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", icon, this.defaultIcon);
- }
-
- ((Component)this).repaint(10L);
- }
-
- public void setIconTextGap(int iconTextGap) {
- this.iconTextGap = iconTextGap;
- ((JComponent)this).firePropertyChange("iconTextGap", iconTextGap, iconTextGap);
- ((Container)this).invalidate();
- ((Component)this).repaint(10L);
- }
-
- public void setLabelFor(Component c) {
- Component oldC = this.labelFor;
- this.labelFor = c;
- ((JComponent)this).firePropertyChange("labelFor", oldC, c);
- }
-
- public void setText(String text) {
- String oldAccessibleName = null;
- if (super.accessibleContext != null) {
- oldAccessibleName = super.accessibleContext.getAccessibleName();
- }
-
- String oldValue = this.text;
- this.text = text;
- ((JComponent)this).firePropertyChange("text", oldValue, text);
- if (super.accessibleContext != null && super.accessibleContext.getAccessibleName() != oldAccessibleName) {
- super.accessibleContext.firePropertyChange("AccessibleVisibleData", oldAccessibleName, super.accessibleContext.getAccessibleName());
- }
-
- ((Component)this).repaint();
- }
-
- public void setUI(LabelUI ui) {
- super.setUI(ui);
- }
-
- public void setVerticalAlignment(int alignment) {
- if (alignment != this.verticalAlignment) {
- int oldValue = this.verticalAlignment;
- this.verticalAlignment = this.checkVerticalKey(alignment, "verticalAlignment");
- ((JComponent)this).firePropertyChange("verticalAlignment", oldValue, this.verticalAlignment);
- ((Component)this).repaint(10L);
- }
- }
-
- public void setVerticalTextPosition(int textPosition) {
- if (textPosition != this.verticalTextPosition) {
- int oldValue = this.verticalTextPosition;
- this.verticalTextPosition = this.checkVerticalKey(textPosition, "verticalTextPosition");
- ((JComponent)this).firePropertyChange("verticalTextPosition", oldValue, this.verticalTextPosition);
- ((Component)this).repaint(10L);
- }
- }
-
- public void updateUI() {
- this.setUI((LabelUI)UIManager.getUI(this));
- ((Container)this).invalidate();
- }
- }
-